﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InformationExtraction.Common
{
    /// <summary>
    /// 由Token组成的在位置上连续的一段文字序列
    /// </summary>
    abstract class TokenSequence : ICloneable
    {
        /// <summary>
        /// 行号或句子号
        /// </summary>
        public int No
        {
            get;
            set;
        }

        /// <summary>
        /// 按Token组织的文本内容
        /// </summary>
        public List<Token> Tokens
        {
            get;
            set;
        }

        /// <summary>
        /// 文本中包含的Token数
        /// </summary>
        public int TokenCount
        {
            get 
            {
                if (Tokens == null)
                    return 0;

                return Tokens.Count;
            }
        }

        /// <summary>
        /// 本段文本内容（不含标签）
        /// </summary>
        public string Content
        {
            get;
            set;
        }

        /// <summary>
        /// 含标注的文本
        /// </summary>
        public string RawContent
        {
            get;
            set;
        }

        /// <summary>
        /// 是否位于所在段落的开始
        /// </summary>
        protected bool IsParagraphHeader
        {
            get;
            set;
        }

        /// <summary>
        /// 是否位于所在段落的结尾
        /// </summary>
        protected bool IsParagraphEnd
        {
            get;
            set;
        }

        /// <summary>
        /// 搜索本行中所有与模式串s相同的字串
        /// </summary>
        /// <param name="s"></param>
        /// <returns>匹配字串的起始位置</returns>
        public List<int> Contain(string s)
        {
            List<int> result = new List<int>();

            int pos = 0;
            while (pos < s.Length)
            {
                pos = Content.IndexOf(s, pos);

                if (pos < 0)
                    break;

                result.Add(pos);
            }

            return result;
        }

        /// <summary>
        /// 下一段文字序列
        /// </summary>
        protected TokenSequence Next
        {
            get;
            set;
        }

        /// <summary>
        /// 上一段文字序列
        /// </summary>
        protected TokenSequence Prior
        {
            get;
            set;
        }

        abstract public Object Clone();        

    }


}
